package com.modxiageasyh.constraintlayoutldemo.fragment

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.modxiageasyh.constraintlayoutldemo.R
import kotlinx.android.synthetic.main.fragment_flow.*

// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

/**
 */
class FlowFragment : Fragment() {
    private var param1: String? = null
    private var param2: String? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            param1 = it.getString(ARG_PARAM1)
            param2 = it.getString(ARG_PARAM2)
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_flow, container, false)
    }
//todo https://developer.android.google.cn/reference/androidx/constraintlayout/helper/widget/Flow?hl=en
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        tv1.setOnClickListener {
            p1.setContentId(R.id.tv1)
        }
        tv2.setOnClickListener {
            p1.setContentId(R.id.tv2)
        }
        tv3.setOnClickListener {
            p1.setContentId(R.id.tv3)
        }
        tv4.setOnClickListener {
            p1.setContentId(R.id.tv4)
        }
        tv5.setOnClickListener {
            p1.setContentId(R.id.tv5)
        }
        iv1.setOnClickListener {
            p1.setContentId(R.id.iv1)
        }
        btn1.setOnClickListener {
            p1.setContentId(R.id.btn1)
        }
    }

    companion object {
        @JvmStatic
        fun newInstance(param1: String, param2: String) =
            FlowFragment().apply {
                arguments = Bundle().apply {
                    putString(ARG_PARAM1, param1)
                    putString(ARG_PARAM2, param2)
                }
            }
    }
}